package com.etxxy.member.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.etxxy.common.exception.DataException;
import com.etxxy.common.exception.ServiceException;
import com.etxxy.member.domain.Member;
import com.etxxy.member.mapper.MemberMapper;
import com.etxxy.member.service.MemberService;

@Service("memberService")
public class MemberServiceImpl implements MemberService {

	private static Logger logger = LoggerFactory.getLogger(MemberServiceImpl.class);
	
	@Autowired
	private MemberMapper memberMapper;

	@Override
	public Member findMemberById(String id) throws ServiceException,DataException {
		Member member  = memberMapper.selectByPrimaryKey(id);
		logger.info("用户数据member={}",JSON.toJSONString(member));
		return member;
	}

	
	@Override
	public Member findMemberByMemberName(String userName) throws ServiceException,DataException {
		logger.info("查找用户userName={}",userName);
		Member member  = memberMapper.findMemberByMemberName(userName);
		return member;
	}


	@Override
	public int insertMember(Member member) throws ServiceException, DataException {
		int result = memberMapper.insert(member);
		return result;
	}


	@Override
	public int updateMember(Member member) throws ServiceException, DataException {
		int result = memberMapper.updateByPrimaryKeySelective(member);
		return result;
	}


	@Override
	public int deleteMember(String id) throws ServiceException, DataException {
		int result = memberMapper.deleteByPrimaryKey(id);
		return result;
	}
	
	@Override
	public PageInfo<Member> selectMember(Member member) throws ServiceException, DataException{
		PageHelper.startPage(1, 10);
		List<Member> members = memberMapper.selectMember(member);
		PageInfo<Member> pageInfo = new PageInfo<Member>(members);
		//pageInfo.setList(members);
		logger.info("pageInfo={}",JSON.toJSONString(pageInfo));
		return pageInfo;
	}

}
